﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package  net.libra.loader.mission{
    import flash.display.*;
    import flash.events.*;
    import flash.system.*;
    import flash.utils.*;
    
    import net.libra.loader.mission.Mission;

    public class LoaderMission extends Mission {

        public var loader:Loader;

        public function LoaderMission(name:String, path:String, useCache:Boolean=true, cacheType:uint=1, key:String=null, data:Object=null){
            super(name, path, useCache, cacheType, key, data);
        }
        protected function handler(event:Event):void{
            loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, handler);
            loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, handler);
            if (event.type == Event.COMPLETE){
                complete();
            } else {
                trace("loader加载失败");
                error();
            };
        }
        override public function convert(source:ByteArray):void{
            if (destroyed){
                return;
            };
            original = source;
            var useBytes:ByteArray = bytes;
            loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handler);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handler);
            loader.loadBytes(useBytes, new LoaderContext(false, applicationDomain));
        }

    }
}//package net.l4cd.loader.mission 
